/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditReportForm.java
 *
 * Created on Apr 14, 2012, 12:03:15 AM
 */
package GUI;

import entities.DoctorDetails;
import entities.PatientDetails;
import entities.ReportDetails;
import entities.StaffDetail;
import entities.Test;
import java.util.ArrayList;
import model.doctor.DoctorComboBoxModel;
import model.patient.PatientComboBoxModel;
import model.staff.StaffComboBoxModel;
import model.test.TestComboBoxModel;
import utilities.DateValidate;
import utilities.ReportManage;
import utilities.SimpleDateFormatter;

/**
 *
 * @author VietLH
 */
public class EditReportForm extends javax.swing.JDialog {

    /** Creates new form EditReportForm */
    public EditReportForm(java.awt.Frame parent, boolean modal,
            ReportDetails reportDetail, ArrayList<DoctorDetails> doctorList,
            ArrayList<StaffDetail> staffList, ArrayList<Test> testList,
            ArrayList<PatientDetails> patientList, ReportManage rm) {
        super(parent, modal);
        initComponents();
        this.optionMessage = new OptionMessage(this);
        this.reportDetail = new ReportDetails();
        this.reportDetail = reportDetail;
        this.testList = new ArrayList<Test>();
        this.staffList = new ArrayList<StaffDetail>();
        this.doctorList = new ArrayList<DoctorDetails>();
        this.patientList = new ArrayList<PatientDetails>();
        this.sdf = new SimpleDateFormatter();
        this.testList = testList;
        this.staffList = staffList;
        this.doctorList = doctorList;
        this.patientList = patientList;
        this.rm = rm;
        dvDOT = new DateValidate(cbDay, cbMonth, cbYear);
        setReportDetail();

        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblPatienName = new javax.swing.JLabel();
        lblAddress = new javax.swing.JLabel();
        lblTestName = new javax.swing.JLabel();
        lblDOBDtl = new javax.swing.JLabel();
        lblTestResult = new javax.swing.JLabel();
        lblDOB = new javax.swing.JLabel();
        lblAddressDtl = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taTestResult = new javax.swing.JTextArea();
        lblStaff = new javax.swing.JLabel();
        lblDoctor = new javax.swing.JLabel();
        lblGender = new javax.swing.JLabel();
        lblGenderDtl = new javax.swing.JLabel();
        lblTestDate = new javax.swing.JLabel();
        cbPatientName = new javax.swing.JComboBox();
        cbTestName = new javax.swing.JComboBox();
        cbStaffName = new javax.swing.JComboBox();
        cbDoctorName = new javax.swing.JComboBox();
        btnUpdate = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        lblStatus = new javax.swing.JLabel();
        cbStatus = new javax.swing.JComboBox();
        cbDay = new javax.swing.JComboBox();
        cbMonth = new javax.swing.JComboBox();
        cbYear = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Edit Report Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), java.awt.Color.blue)); // NOI18N

        lblPatienName.setText("Patient Name:");

        lblAddress.setText("Address:");

        lblTestName.setText("Test Name:");

        lblDOBDtl.setText("jLabel5");

        lblTestResult.setText("Test Result:");

        lblDOB.setText("Date of birth:");

        lblAddressDtl.setText("jLabel9");

        taTestResult.setColumns(20);
        taTestResult.setRows(5);
        taTestResult.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                taTestResultFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                taTestResultFocusLost(evt);
            }
        });
        taTestResult.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                taTestResultKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(taTestResult);

        lblStaff.setText("Staff:");

        lblDoctor.setText("Doctor:");

        lblGender.setText("Gender:");

        lblGenderDtl.setText("jLabel2");

        lblTestDate.setText("Test Date:");

        cbPatientName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbPatientName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPatientNameActionPerformed(evt);
            }
        });

        cbTestName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbTestName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTestNameActionPerformed(evt);
            }
        });

        cbStaffName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbStaffName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbStaffNameActionPerformed(evt);
            }
        });

        cbDoctorName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbDoctorName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDoctorNameActionPerformed(evt);
            }
        });

        btnUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Icons/check2.png"))); // NOI18N
        btnUpdate.setText("Update");
        btnUpdate.setEnabled(false);
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Icons/Cancel-16.png"))); // NOI18N
        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        lblStatus.setText("Status:");

        cbStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Not Started", "In Progress", "Finished" }));
        cbStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbStatusActionPerformed(evt);
            }
        });

        cbDay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbDay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDayActionPerformed(evt);
            }
        });

        cbMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbMonthActionPerformed(evt);
            }
        });

        cbYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbYearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPatienName)
                            .addComponent(lblDOB)
                            .addComponent(lblTestName)
                            .addComponent(lblAddress)
                            .addComponent(lblTestDate))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblAddressDtl)
                            .addComponent(lblDOBDtl)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(cbTestName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(cbPatientName, 0, 175, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(cbDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbYear, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lblStatus)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(cbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lblGender)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblGenderDtl, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(lblDoctor)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(cbDoctorName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(lblStaff)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbStaffName, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))
                        .addGap(90, 90, 90))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnUpdate)
                        .addGap(18, 18, 18)
                        .addComponent(btnClose)
                        .addGap(134, 134, 134))
                    .addComponent(lblTestResult))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPatienName)
                    .addComponent(cbPatientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblGender)
                    .addComponent(lblGenderDtl))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDOB)
                    .addComponent(lblDOBDtl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAddress)
                    .addComponent(lblAddressDtl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTestName)
                    .addComponent(cbTestName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblStatus)
                    .addComponent(cbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTestDate)
                    .addComponent(cbDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblTestResult)
                .addGap(15, 15, 15)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblStaff)
                    .addComponent(cbStaffName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDoctor)
                    .addComponent(cbDoctorName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUpdate)
                    .addComponent(btnClose))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 479, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbPatientNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPatientNameActionPerformed
        // TODO add your handling code here:
        cbPatientNameChangeAction();
    }//GEN-LAST:event_cbPatientNameActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        // TODO add your handling code here:
        optionMessage.confirmExit();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        // TODO add your handling code here:
        updateReport();
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void cbTestNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTestNameActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbTestNameActionPerformed

    private void cbStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStatusActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbStatusActionPerformed

    private void cbStaffNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStaffNameActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbStaffNameActionPerformed

    private void cbDoctorNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDoctorNameActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbDoctorNameActionPerformed

    private void taTestResultFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_taTestResultFocusLost
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_taTestResultFocusLost

    private void taTestResultFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_taTestResultFocusGained
        // TODO add your handling code here:
//        this.btnUpdate.setEnabled(true);
    }//GEN-LAST:event_taTestResultFocusGained

    private void taTestResultKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_taTestResultKeyTyped
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_taTestResultKeyTyped

    private void cbDayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDayActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbDayActionPerformed

    private void cbMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMonthActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbMonthActionPerformed

    private void cbYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbYearActionPerformed
        // TODO add your handling code here:
        makeChange();
    }//GEN-LAST:event_cbYearActionPerformed

    private void cbPatientNameChangeAction() {
        this.lblAddressDtl.setText(((PatientDetails) cbPatientName.getSelectedItem()).getpAddress());
        this.lblDOBDtl.setText(((PatientDetails) cbPatientName.getSelectedItem()).getpDOB().toString());
        if (((PatientDetails) cbPatientName.getSelectedItem()).ispGender()) {
            this.lblGenderDtl.setText("Male");
        } else {
            this.lblGenderDtl.setText("Female");
        }
        makeChange();
    }

    private void setReportDetail() {
        this.lblAddressDtl.setText(reportDetail.getPatientDetails().getpAddress());
        this.lblDOBDtl.setText(reportDetail.getPatientDetails().getpDOB().toString());
        PatientComboBoxModel pcm = new PatientComboBoxModel(patientList);
        TestComboBoxModel tcm = new TestComboBoxModel(testList);
        DoctorComboBoxModel dcm = new DoctorComboBoxModel(doctorList);
        StaffComboBoxModel scm = new StaffComboBoxModel(staffList);
        //this.cbDoctorName.setSelectedItem(reportDetail.getDoctorDetails());
        dcm.setSelectedItem(reportDetail.getDoctorDetails());
        pcm.setSelectedItem(reportDetail.getPatientDetails());
        scm.setSelectedItem(reportDetail.getStaffDetail());
        tcm.setSelectedItem(reportDetail.getTest());

        this.cbPatientName.setModel(pcm);
        this.cbTestName.setModel(tcm);
        this.cbDoctorName.setModel(dcm);
        this.cbStaffName.setModel(scm);
        this.taTestResult.setText(reportDetail.getReport());

        if (reportDetail.getPatientDetails().ispGender()) {
            this.lblGenderDtl.setText("Male");
        } else {
            this.lblGenderDtl.setText("Female");
        }
        this.cbStatus.setSelectedIndex(reportDetail.getStatus() + 1);
        this.cbDay.setSelectedIndex(sdf.getDay(reportDetail.getTestDate()));
        this.cbMonth.setSelectedIndex(sdf.getMonth(reportDetail.getTestDate()));
        this.cbYear.setSelectedIndex(sdf.getYear(reportDetail.getTestDate()));
    }

    private void updateReport() {
        this.btnUpdate.setEnabled(false);
        this.reportDetail.setDoctorDetails((DoctorDetails) cbDoctorName.getSelectedItem());
        this.reportDetail.setPatientDetails((PatientDetails) cbPatientName.getSelectedItem());
        this.reportDetail.setReport(taTestResult.getText());
        this.reportDetail.setStaffDetail((StaffDetail) cbStaffName.getSelectedItem());
        this.reportDetail.setStatus(cbStatus.getSelectedIndex() - 1);
        this.reportDetail.setTest((Test) cbTestName.getSelectedItem());
        String DOBstr = (cbMonth.getSelectedIndex() + 1) + "/" + (cbDay.getSelectedIndex() + 1) + "/" + (cbYear.getSelectedIndex() + 1900);
        this.reportDetail.setTestDate(sdf.convertStringToDate(DOBstr));
        if (rm.editReport(reportDetail)) {
            this.dispose();
        }
    }

    private void makeChange() {
        if ((cbPatientName.getSelectedItem() instanceof PatientDetails)
                && (cbDoctorName.getSelectedItem() instanceof DoctorDetails)
                && (cbStaffName.getSelectedItem() instanceof StaffDetail)
                && (cbTestName.getSelectedItem() instanceof Test)) {
            boolean isChange = false;
            String day = Integer.toString(cbDay.getSelectedIndex() + 1);
            if (day.length() < 2) {
                day = "0" + day;
            }
            String month = Integer.toString(cbMonth.getSelectedIndex() + 1);
            if (month.length() < 2) {
                month = "0" + month;
            }
            String year = Integer.toString((cbYear.getSelectedIndex() + 1900));
            String DOBstr = (day + "/" + month + "/" + year);
            String curTestDate = sdf.convertDateToString(reportDetail.getTestDate());
            if (reportDetail.getPatientDetails().getpID() != ((PatientDetails) cbPatientName.getSelectedItem()).getpID()) {
                isChange = true;
            } else if (reportDetail.getTest().getTestID() != ((Test) cbTestName.getSelectedItem()).getTestID()) {
                isChange = true;
            } else if (reportDetail.getStatus() != (cbStatus.getSelectedIndex() - 1)) {
                isChange = true;
            } else if (reportDetail.getDoctorDetails().getdID() != ((DoctorDetails) cbDoctorName.getSelectedItem()).getdID()) {
                isChange = true;
            } else if (reportDetail.getStaffDetail().getStaffID() != ((StaffDetail) cbStaffName.getSelectedItem()).getStaffID()) {
                isChange = true;
            } else if (reportDetail.getReport().compareTo(this.taTestResult.getText()) != 0) {
                isChange = true;
            } else if (curTestDate.compareTo(DOBstr) != 0) {
                isChange = true;
            }
            if (isChange) {
                this.btnUpdate.setEnabled(true);
            } else {
                this.btnUpdate.setEnabled(false);
            }
        } 
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(EditReportForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(EditReportForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(EditReportForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(EditReportForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the dialog */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                EditReportForm dialog = new EditReportForm(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cbDay;
    private javax.swing.JComboBox cbDoctorName;
    private javax.swing.JComboBox cbMonth;
    private javax.swing.JComboBox cbPatientName;
    private javax.swing.JComboBox cbStaffName;
    private javax.swing.JComboBox cbStatus;
    private javax.swing.JComboBox cbTestName;
    private javax.swing.JComboBox cbYear;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblAddressDtl;
    private javax.swing.JLabel lblDOB;
    private javax.swing.JLabel lblDOBDtl;
    private javax.swing.JLabel lblDoctor;
    private javax.swing.JLabel lblGender;
    private javax.swing.JLabel lblGenderDtl;
    private javax.swing.JLabel lblPatienName;
    private javax.swing.JLabel lblStaff;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblTestDate;
    private javax.swing.JLabel lblTestName;
    private javax.swing.JLabel lblTestResult;
    private javax.swing.JTextArea taTestResult;
    // End of variables declaration//GEN-END:variables
    private ReportDetails reportDetail;
    private ArrayList<DoctorDetails> doctorList;
    private ArrayList<StaffDetail> staffList;
    private ArrayList<PatientDetails> patientList;
    private ArrayList<Test> testList;
    private OptionMessage optionMessage;
    private ReportManage rm;
    private DateValidate dvDOT = new DateValidate();
    private SimpleDateFormatter sdf;
}
